/**
 * @author Andrey Anisimov <hercules@inbox.ru>
 */

import core.util.Listeners;

class AbstractTimer {

    /**
     * @public
     * @constructor
     */
    this.AbstractTimer = function() {
        this.listeners = new Listeners([
            'onTimerStarted',
            'onTimerPaused',
            'onTimerResumed',
            'onTimerStopped',
            'onTimer'
        ]);
    };

    /**
     * @public
     * @param l {Object} Object implementing any of the following methods:
     * <ul>
     *     <li><code>onTimerStarted</code></li>
     *     <li><code>onTimerPaused</code></li>
     *     <li><code>onTimerResumed</code></li>
     *     <li><code>onTimer</code></li>
     *     <li><code>onTimerStopped</code></li>
     * </ul>
     */
    this.addTimerListener = function(l) {
        this.listeners.add(l);
    };

    /**
     * @public
     * @param l {Object}
     */
    this.removeTimerListener = function(l) {
        this.listeners.remove(l);
    };

    /**
     * @abstract
     * @public
     */
    this.start = function() {
        throw new Error('AbstractTimer.start is abstract!');
    };

    /**
     * @abstract
     * @public
     */
    this.stop = function() {
        throw new Error('AbstractTimer.stop is abstract!');
    };

    /**
     * @abstract
     * @public
     */
    this.pause = function() {
        throw new Error('AbstractTimer.pause is abstract!');
    };

    /**
     * @abstract
     * @public
     */
    this.resume = function() {
        throw new Error('AbstractTimer.resume is abstract!');
    };

    /**
     * @abstract
     * @public
     * @return {Boolean}
     */
    this.isStarted = function() {
        throw new Error('AbstractTimer.isStarted is abstract!');
    };

    /**
     * @abstract
     * @public
     * @return {Date}
     */
    this.getStartTime = function() {
        throw new Error('AbstractTimer.getStartTime is abstract!');
    };

    /**
     * @protected
     */
    this.fireTimer = function() {
//        Profiler.begin('timer');
        this.listeners.call('onTimer', [ this ]);
//        Profiler.end('timer');
    };

    /**
     * @protected
     */
    this.fireStarted = function() {
        this.listeners.call('onTimerStarted', [ this ]);
    };

    /**
     * @protected
     */
    this.firePaused = function() {
        this.listeners.call('onTimerPaused', [ this ]);
    };

    /**
     * @protected
     */
    this.fireResumed = function() {
        this.listeners.call('onTimerResumed', [ this ]);
    };

    /**
     * @protected
     */
    this.fireStopped = function() {
        this.listeners.call('onTimerStopped', [ this ]);
    };
}